from time import sleep

from selenium.webdriver.common.by import By
import allure
from util_tools.basePage import BasePage

class AddDishCategoryPage(BasePage):
    url = '/category'
    # 分类管理
    manage_category = (By.XPATH, '//*[@id="app"]/div/div[1]/div[2]/div[1]/div/ul/div[7]/div/a/li/span')
    # 新增菜品分类
    add_dish_category_but = (By.XPATH, '//*[@id="app"]/div/div[2]/section/div/div[1]/div[1]/div[3]/button[1]')
    # 名称
    name = (By.XPATH, '//*[@id="app"]/div/div[2]/section/div/div[2]/div/div[2]/form/div[1]/div/div/input')
    # 排序
    sort = (By.XPATH, '//*[@id="app"]/div/div[2]/section/div/div[2]/div/div[2]/form/div[2]/div/div/input')
    # 确定按钮
    confirm = (By.XPATH, '//*[@id="app"]/div/div[2]/section/div/div[2]/div/div[3]/span/button[2]/span')
    # 失败断言
    fail_assert = (By.XPATH, '//*[@id="app"]/div/div[2]/section/div/div[2]/div/div[1]/span')


    def add_dish_category(self, name, sort):
        self.open_url(self.url)
        allure.attach(self.url, '打开菜品测试页面', attachment_type=allure.attachment_type.TEXT)
        # 点击分类管理
        self.click(self.manage_category)
        # 点击新增菜品分类
        self.click(self.add_dish_category_but)
        # 输入名称
        self.send_keys(self.name, name)
        # 输入排序
        self.send_keys(self.sort, sort)
        # 点击确定按钮
        self.click(self.confirm)
        sleep(1.5)
        allure.attach(self.screenshots_png(), f'{name}:新增菜品', attachment_type=allure.attachment_type.PNG)
